package com.Dec_Nineteen;

public class Solution807 {

    public int maxIncreaseKeepingSkyline(int[][] grid) {
        int n=grid.length,ans=0;
        int[] r=new int[n];
        int[] c=new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                r[i]=Math.max(r[i],grid[i][j]);
                c[j]=Math.max(c[j],grid[i][j]);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                ans+=Math.min(r[i],c[j])-grid[i][j];
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution807 solution807=new Solution807();
        System.out.println(solution807.maxIncreaseKeepingSkyline(new int[][]{{3,0,8,4},{2,4,5,7},{9,2,6,3},{0,3,1,0}}));
    }

}
